﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lacrima.Gobang.Infrastructure
{
    public class CustomProgressBar : ProgressBar
    {
        protected Font font = new Font("Times New Roman", (float)11, FontStyle.Bold);

        protected string progressContext
        {
            get
            {
                return string.Concat(this.Value,"%");
            }
        }

        protected PointF pt
        {
            get
            {
                return new PointF(this.Width / 2 - 10, this.Height / 2 - 10);
            }
        }

        protected Rectangle bounds
        {
            get
            {
                return new Rectangle(0, 0, base.Width, base.Height);
            }
        }

        public CustomProgressBar ()
        {
            base.SetStyle(ControlStyles.UserPaint, true);
        }

        /// <summary>
        /// 重写空间的绘制事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            SolidBrush brush = null;
            var bounds = this.bounds;
            e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width, bounds.Height);
            bounds.Height -= 3;
            bounds.Width = ((int)(bounds.Width * (((double)base.Value) / ((double)base.Maximum)))) - 4;
            brush = new SolidBrush(Color.Green);
            e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);

            if(this.Value > this.Minimum)
            {
                if(this.Value==this.Maximum)
                {
                    this.CreateGraphics().DrawString("完成", font, Brushes.Black, pt);
                }
                else
                {
                    this.CreateGraphics().DrawString(progressContext, font, Brushes.Black, pt);
                }
            }
        }
    }
}
